<template>
  <div>
    <div class="head">
      <div class="iconfont iconjiantou" @click="getback"></div>
      <div class="inputbox">
        <div class="iconfont iconsearch"></div>
        <input type="text" v-model="keyword" placeholder="请输入" />
      </div>
      <div class="search" @click="searchtext">搜索</div>
    </div>
    <div class="record">
      <div class="message">
        <p>历史记录</p>
        <div class="text">你好</div>
      </div>
    </div>
    <div class="center">
      <Postcenter
        :Postdata="itme"
        v-for="itme in postlist"
        :key="itme.id"
      ></Postcenter>
    </div>
  </div>
</template>

<script>
import Postcenter from "../../components/Postcenter";
export default {
  components: { Postcenter },
  data() {
    return {
      keyword: "",
      postlist: [],
    };
  },

  methods: {
    searchtext() {
      this.$axios({
        url: "post_search",
        params: {
          keyword: this.keyword,
        },
      }).then((res) => {
        console.log(res.data);
        if (this.keyword.length > 0) {
          this.postlist = res.data.data;
          this.keyword = "";
        } else {
          this.$toast("请输入内容");
        }
      });
    },
    getback() {
      if (this.postlist.length > 0) {
        this.postlist = [];
      } else {
        this.$router.back();
      }
    },
  },
};
</script>

<style lang="less" scoped>
.head {
  margin: 10/360 * 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  .iconjiantou {
    font-size: 20/360 * 100vw;
  }
  .inputbox {
    margin-left: 8/360 * 100vw;
    border-radius: 19/360 * 100vw;
    display: flex;
    width: 260/360 * 100vw;
    height: 38/360 * 100vw;
    border: turquoise solid 2px;
    .iconsearch {
      font-size: 20/360 * 100vw;
      margin: 7/360 * 100vw 0 4/360 * 100vw 10/360 * 100vw;
    }
    input {
      font-size: 16/360 * 100vw;
      margin: 8/360 * 100vw 0 6/360 * 100vw 10/360 * 100vw;
      width: 200/360 * 100vw;
      height: 20/360 * 100vw;
      border: none;
      line-height: 20/360 * 100vw;
    }
  }
  .search {
    margin-left: 10/360 * 100vw;
    font-size: 18/360 * 100vw;
  }
}
.record {
  border-bottom: #e4e4e4 solid 2px;
  .message {
    margin: 10/360 * 100vw 0 15/360 * 100vw 20/360 * 100vw;
    p {
      font-weight: 700;
    }
    .text {
      color: #888;
      font-size: 16/360 * 100vw;
    }
  }
}
</style>